package com.sudo.controller;

import com.sudo.aspect.AuthorizationApi;
import com.sudo.common.utils.JsonRes;
import com.sudo.pojo.SysCpuLog;
import com.sudo.pojo.SysInfo;
import com.sudo.pojo.SysMemLog;
import com.sudo.service.SysCpuLogService;
import com.sudo.service.SysInfoService;
import com.sudo.service.SysMemLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author：为道日损 2020-07-07 11:18
 * webSite：https://www.sudo.ren
 */
@Api(value = "监控信息",tags = {"监控信息相关的接口"})
@RestController
@RequestMapping("sysInfo")
public class SysInfoController {

    @Autowired
    private SysInfoService sysInfoService;

    @Autowired
    private SysMemLogService sysMemLogService;

    @Autowired
    private SysCpuLogService sysCpuLogService;

    @AuthorizationApi(menu = "server_monitor",button = "search")
    @ApiOperation(value = "查询所有的基础监控信息",notes = "查询所有的基础监控信息",httpMethod = "GET")
    @GetMapping("getAllBasicMonitorInfo")
    public JsonRes getAllBasicMonitorInfo() {
        List<SysInfo> sysInfoList = sysInfoService.getAllSysInfo();
        return JsonRes.ok(sysInfoList);
    }

    @AuthorizationApi(menu = "server_monitor",button = "search")
    @ApiOperation(value = "获取cpu实时信息",notes = "获取cpu实时信息",httpMethod = "GET")
    @GetMapping("getCpuInfoActualTime")
    public JsonRes getCpuInfoActualTime(@RequestParam("num") Integer num) {
        List<SysCpuLog> sysCpuLogList = sysCpuLogService.getCpuLogListFromRedis(num);
        return JsonRes.ok(sysCpuLogList);
    }

    @AuthorizationApi(menu = "server_monitor",button = "search")
    @ApiOperation(value = "获取内存实时信息",notes = "获取内存实时信息",httpMethod = "GET")
    @GetMapping("getMemInfoActualTime")
    public JsonRes getMemInfoActualTime(@RequestParam("num") Integer num) {
        List<SysMemLog> sysMemLogList = sysMemLogService.getMemLogListFromRedis(num);
        return JsonRes.ok(sysMemLogList);
    }
}
